<template>
  <div class="body">
    <div class="top">
      <div class="item">
        <el-icon style=" transform:translateY(2px)">
          <Cellphone/>
        </el-icon>
        <span>账号查找</span>
        <input type="text" placeholder="请输入内容" v-model="tel">
        <button @click="findBytel">搜索</button>
      </div>
      <div class="span"></div>
      <div class="item">
        <el-icon style=" transform:translateY(2px)">
          <Film/>
        </el-icon>
        <span>租赁码查找</span>
        <input type="text" placeholder="请输入内容" v-model="code">
        <button @click="findBycode">搜索</button>
      </div>
    </div>
    <div class="main">
      <el-table row-key="date" :data="data" style="width: 100%"
      >
        <el-table-column
            prop="code"
            label="租赁码"
            width="300"
            column-key="code"
            class-name="column"
            class="column"

        />
        <el-table-column prop="qq" label="邮箱" width="300" align="left"/>
        <el-table-column prop="updatedat" label="时间" width="300" align="left"/>


        <el-table-column
            prop="status"
            label="等级"
            width="300"
            align="left"
            :filters="[
        { text: '黄金', value: '黄金' },
        { text: '白银', value: '白银' },
          { text: '青铜', value: '青铜' },
      ]"
            :filter-method="filterTag"
            filter-placement="bottom-end"
        >
          <template #default="scope">
            <el-tag

                :type="tag[scope.row.grade]"
                disable-transitions
            >{{ scope.row.grade }}
            </el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="Operations" width="120" fixed="right">
          <template #default="scope">
            <el-button link type="primary" size="small" @click.prevent="refund(scope.row)">修改</el-button>
          </template>
        </el-table-column>

      </el-table>
      <el-pagination background layout="prev, pager, next" :total="total" @current-change="handleCurrentChange"/>
    </div>
  </div>
</template>

<script setup>
import {
  ref,
  reactive, inject, onMounted
} from "vue";
import copy from '../utils/copy'

const axios = inject('$axios')
const tag = reactive({
  "黄金": "",
  "白银": "sucess",
  "青铜": "danger",

})
const code = ref("")
const tel = ref("")
const total = ref(0)
const data = reactive([
  {
    code: "",
    grade: "",
    tel: "",
    updatedat: ""
  }
])
const findBytel = () => {
  if (!tel.value.length) {
    alert("请输入信息")
  } else {
    axios.get("/log/qq?qq=" + tel.value.trim()).then(res => {
      data.splice(0, data.length)
      copy(res.data.data.data, data)
      total.value = res.data.data.p * 10
    }).catch(err => {

    })

  }
}
const findBycode = () => {
  if (!code.value.length) {
    alert("请输入信息")
  } else {
    axios.get("/log/code?code=" + code.value.trim()).then(res => {
      data.splice(0, data.length)
      copy(res.data.data.data, data)
      console.log(res)
      total.value = res.data.data.p * 10
    }).catch(err => {

    })
  }
}
const handleCurrentChange = val => {
  axios.get("/log?p=" + val + "&s=10").then(res => {
    console.log(res)
    copy(res.data.data.data, data)
    total.value = res.data.data.p * 10
  }).catch(err => {

  })
}


onMounted(() => {
  axios.get("/log?p=1&s=10").then(res => {
    console.log(res)
    copy(res.data.data.data, data)
    total.value = res.data.data.p * 10
  }).catch(err => {

  })
})
const filterTag = (value, row) => {
  return row.grade === value
}
const refund = i =>{
  console.log(i.qq,i.grade)
}
</script>

<style scoped lang="less">
.el-table th {
  padding: 0 !important;

}

.body {
  width: 100%;
  height: 100%;

  .main {
    width: 80%;
    max-width: 1150px;
    margin: 10px auto;
    color: red !important;
    padding: 0 !important;
  }

  .top {
    width: 80%;
    height: 100px;
    background-color: #ffffff;
    border-radius: 10px;
    margin: 10px auto;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
  }

  .item {
    font-size: 17px;
    color: #606266;

    input {
      width: 300px;
      height: 30px;
      border: 1px solid #409EFF;
      background-color: #ffffff;
      border-radius: 10px 0 0 10px;
      text-indent: 1em;
      margin-left: 10px;
    }

    button {
      width: 50px;
      height: 32px;
      border-radius: 0 10px 10px 0;
      color: #fff;
      background-color: #409EFF;
      border: 2px solid #409EFF;
    }

    span {
      margin-left: 5px;
    }

  }

  .span {
    margin: auto 20px;
  }
}
</style>